.PHONY: help install dev test clean docker-build docker-run migrate init-db

# 默认目标
help:
	@echo "企业管理系统开发工具"
	@echo ""
	@echo "可用命令:"
	@echo "  install     - 安装依赖"
	@echo "  dev         - 启动开发服务器"
	@echo "  test        - 运行测试"
	@echo "  migrate     - 创建数据库迁移"
	@echo "  init-db     - 初始化数据库"
	@echo "  clean       - 清理缓存和临时文件"
	@echo "  docker-build - 构建Docker镜像"
	@echo "  docker-run  - 运行Docker容器"
	@echo "  docker-compose - 使用Docker Compose启动服务"

# 安装依赖
install:
	pip install -r requirements.txt

# 启动开发服务器
dev:
	python start.py

# 运行测试
test:
	pytest tests/ -v

# 创建数据库迁移
migrate:
	alembic revision --autogenerate -m "$(m)"

# 应用数据库迁移
upgrade:
	alembic upgrade head

# 初始化数据库
init-db:
	python scripts/init_db.py

# 清理缓存和临时文件
clean:
	find . -type f -name "*.pyc" -delete
	find . -type d -name "__pycache__" -delete
	find . -type d -name "*.egg-info" -exec rm -rf {} +
	rm -rf .pytest_cache
	rm -rf build/
	rm -rf dist/

# Docker相关命令
docker-build:
	docker build -t enterprise-backend .

docker-run:
	docker run -d -p 8000:8000 --env-file .env enterprise-backend

docker-compose:
	docker-compose up --build

# 生产环境部署
prod:
	uvicorn app.main:app --host 0.0.0.0 --port 8000 --workers 4